import time

from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait

from Driver.Driver import MDriver
from part import BarFace

class Froum:
    driver=''
    def __init__(self):
        self.driver=MDriver.driver
    # 进入论坛主页
    def Come(self):
        BarFace.BarFace().Come()
    # 方便写代码
    def QFind(self,name):
        self.driver.find_element(By.CSS_SELECTOR,name)
    # 界面元素检测
    def ForumFace(self):
        # 发布帖子按钮
        self.QFind("#bit-forum-content > div.page-header.d-print-none > div > div > div.col-auto.ms-auto.d-print-none > div > a.btn.btn-primary.d-none.d-sm-inline-block.article_post")
        # 帖子标题
        self.QFind("#artical-items-body > div:nth-child(1) > div > div.col > div.text-truncate > a")
        # 首页文字
        self.QFind("#article_list_board_title")
        # 帖子作者要头像
        self.QFind("#artical-items-body > div:nth-child(1) > div > div.col-auto > span")
        # 帖子发布者任务图标及姓名
        self.QFind("#artical-items-body > div:nth-child(1) > div > div.col > div.text-muted.mt-2 > div > div.col > ul > li:nth-child(1)")
        # 帖子时间
        self.QFind("#artical-items-body > div:nth-child(1) > div > div.col > div.text-muted.mt-2 > div > div.col > ul > li:nth-child(2)")
        # 帖子观看量
        self.QFind("#artical-items-body > div:nth-child(1) > div > div.col > div.text-muted.mt-2 > div > div.col-auto.d-none.d-md-inline > ul > li:nth-child(1)")
        # 帖子点赞量
        self.QFind("#artical-items-body > div:nth-child(1) > div > div.col > div.text-muted.mt-2 > div > div.col-auto.d-none.d-md-inline > ul > li:nth-child(2)")
        # 帖子评论量
        self.QFind("#artical-items-body > div:nth-child(1) > div > div.col > div.text-muted.mt-2 > div > div.col-auto.d-none.d-md-inline > ul > li:nth-child(3)")
    # 进入帖子编辑页
    def ForumGotoSendPost(self):
        self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-header.d-print-none > div > div > div.col-auto.ms-auto.d-print-none > div > a.btn.btn-primary.d-none.d-sm-inline-block.article_post").click()
    # 进入帖子
    def ForumOpenPost(self,selector):
        self.driver.execute_script("arguments[0].scrollIntoView();",self.driver.find_element(By.CSS_SELECTOR,selector))
        time.sleep(1)
        self.driver.find_element(By.CSS_SELECTOR,selector).click()
    # 返回主页
    def GoHome(self):
        self.driver.execute_script("arguments[0].scrollIntoView();",self.driver.find_element(By.CSS_SELECTOR,"#nav_board_index > a"))
        time.sleep(1)
        BarFace.BarFace().BarHome()
